package com.xyebank.ledger.service.sjdzadd.dataProvider.repay;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.vo.deal.ZADDSjdCashRepayVo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class ZADDSjdCashRepayProvider implements DataProvider<ZADDSjdCashRepayVo> {

	@Autowired
	private ZADDSjdCashRepayMapper zaddSjdRepayPlanMapper;

	@Override
	public List<ZADDSjdCashRepayVo> get(Integer fromIdx, Integer tarNum) {
		List<ZADDSjdCashRepay> result = zaddSjdRepayPlanMapper.selectByPaging(fromIdx, tarNum);
		List<ZADDSjdCashRepayVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public List<ZADDSjdCashRepayVo> get(Date timeStart, Date timeEnd, Integer fromIdx, Integer tarNum) {
		List<ZADDSjdCashRepay> result = zaddSjdRepayPlanMapper.selectByPeriod(DateUtil.getFormatDate(timeStart), DateUtil.getFormatDate(timeEnd), fromIdx, tarNum);
		List<ZADDSjdCashRepayVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public Integer count(Date timeStart, Date timeEnd) {
		Integer count = zaddSjdRepayPlanMapper.selectPeriodCount(DateUtil.getFormatDate(timeStart), DateUtil.getFormatDate(timeEnd));
		return count;
	}

	private List<ZADDSjdCashRepayVo> convert2Vo(List<ZADDSjdCashRepay> result) {
		List<ZADDSjdCashRepayVo> list = new ArrayList<ZADDSjdCashRepayVo>();
		for (int i = 0; i < result.size(); i++) {
			ZADDSjdCashRepayVo vo = new ZADDSjdCashRepayVo();
			BeanUtils.copyProperties(result.get(i), vo);
			list.add(vo);
		}
		return list;
	}

}
